package ME.VPC.S.buttons;

import ME.VPC.M.app.App;
import ME.VPC.S.ne.Page_X_S_sVSQ;
import M_V.MVQ.button.DetaButton;
import P.image.Color_P;
import S_A.AVQ.OVQ.OSQ.VSQ.obj.WordFrequency;
import S_A.SVQ.stable.S_Maps;
import S_A.SVQ.stable.S_Pos;
import S_A.pheromone.IMV_SQI_SS;
import S_A.pheromone.IMV_SQI_S_;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.List;
//import OCI.ME.analysis.C.A;
//import OSV.VCQ.standard.DictionaryStandardDB;

/*
 * 个人著作权人, 作者 罗瑶光, 浏阳
 * yaoguangluo@outlook.com, 313699483@qq.com, 2080315360@qq.com,
 * （lyg.tin@gmail.com2018年后因G网屏蔽不再使用）
 ** 15116110525-浏阳德塔软件开发有限公司-创始人-法人-总经理-永久非盈利-
 * 430181198505250014, G24402609, EB0581342
 * 204925063, 389418686, F2406501, 0626136
 * 湖南省 浏阳市 集里街道 神仙坳社区 大塘冲路一段
*  208号 阳光家园别墅小区 第十栋别墅 第三层
 * */
//rollback= later~
public class Page_X_S_sButtonsrollback {
	public static DetaButton data_X_rollback(Page_X_S_sVSQ page_X_S_s,
			int maxInPage, App NE) {
		DetaButton buttonPrev = new DetaButton("<-");
		// buttonPrev.setBounds(290, 0, 100, 30);
		buttonPrev.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {// later short chars.
				IMV_SQI_SS map = new IMV_SQI_SS();
				page_X_S_s.currentPage -= 1;
				page_X_S_s.currentPage = (page_X_S_s.currentPage < 0 ? 0
						: page_X_S_s.currentPage);
				StringBuilder page = new StringBuilder().append("");
				List<String> setsForGet = page_X_S_s.sets.subList(
						page_X_S_s.currentPage * maxInPage,
						(page_X_S_s.currentPage + 1)
								* maxInPage < page_X_S_s.sets.size()
										? (page_X_S_s.currentPage + 1)
												* maxInPage
										: page_X_S_s.sets.size());
				Iterator<String> iterator = setsForGet.iterator();
				NE.app_S.listCharPosition = 0;
				Here: while (iterator.hasNext()) {
					NE.app_S.listCharPosition++;
					String setOfi = iterator.next();
					if (page_X_S_s.pos.get(setOfi) == null) {
						page.append("<span style=\"background:#ffffff\">"
								+ "<font color=\"black\"" + " size=\""
								+ NE.app_S.size_font_rot + "\">" + setOfi
								+ "</font></span>");
						continue Here;
					}
					if (S_Maps.mingCi.containsKey(setOfi)
							|| S_Maps.dongCi.containsKey(setOfi)
							|| S_Maps.xingRongCi.containsKey(setOfi)) {
						if (map.containsKey(setOfi)) {
							WordFrequency wordFrequency = map.getW(setOfi);
							wordFrequency
									.I_frequency(wordFrequency.get_frequency()
											+ S_Pos.INT_ONE);
							wordFrequency.positions
									.add(NE.app_S.listCharPosition);
							map.put(setOfi, wordFrequency);
						} else {
							WordFrequency wordFrequency = new WordFrequency(1.0,
									setOfi);
							wordFrequency.positions
									.add(NE.app_S.listCharPosition);
							map.put(setOfi, wordFrequency);
						}
					}
					if (!setOfi.equals("")) {
						if (page_X_S_s.key.contains(setOfi) && (S_Maps.mingCi
								.containsKey(setOfi)
								|| S_Maps.dongCi.containsKey(setOfi)
								|| S_Maps.xingRongCi.containsKey(setOfi))) {
							page.append("<span style=\"background:red\">"
									+ "<font color=\"white\">" + setOfi
									+ "</font></span>");
							continue Here;
						}
						if (S_Maps.mingCi.containsKey(setOfi)) {
							page.append("<span style=\"background:"
									+ Color_P.P(245,
											205 - page_X_S_s.app_S.raterot << 3,
											245)
									+ "\"><font color=" + Color_P.P(0, 0, 0)
									+ " size=\"" + NE.app_S.size_font_rot
									+ "\">" + setOfi + "</font></span>");
							continue Here;
						}
						if (S_Maps.dongCi.containsKey(setOfi)) {
							page.append("<span style=\"background:" + Color_P.P(
									245 - page_X_S_s.app_S.raterot << 3, 245,
									205 - page_X_S_s.app_S.raterot << 3)
									+ "\"><font color=" + Color_P.P(0, 0, 0)
									+ " size=\"" + NE.app_S.size_font_rot
									+ "\">" + setOfi + "</font></span>");
							continue Here;
						}
						if (S_Maps.xingRongCi.containsKey(setOfi)) {
							page.append("<span style=\"background:"
									+ Color_P.P(245, 245, 245 - 40
											- page_X_S_s.app_S.raterot << 3)
									+ "\"><font color=" + Color_P.P(0, 0, 0)
									+ " size=\"" + NE.app_S.size_font_rot
									+ "\">" + setOfi + "</font></span>");
							continue Here;
						}
						if (S_Maps.fuCi.containsKey(setOfi)) {
							page.append("<span style=\"background:#f1ffff\">"
									+ "<font color=\"black\"" + " size=\""
									+ NE.app_S.size_font_rot + "\">" + setOfi
									+ "</font></span>");
							continue Here;
						}
						page.append("<span style=\"background:white\">"
								+ "<font color=\"black\"" + " size=\""
								+ NE.app_S.size_font_rot + "\">" + setOfi
								+ "</font></span>");
					}
				}
				page_X_S_s.buttonCrt
						.setText("当前页面：" + (page_X_S_s.currentPage + 1));
				page_X_S_s.data.setText(page.toString());
				page_X_S_s.data.setSelectionStart(0);
				page_X_S_s.data.setSelectionEnd(0);
				page_X_S_s.data.validate();
				page_X_S_s.statistic.setSize(500, 800);
				IMV_SQI_S_ fwa = page_X_S_s._A
						.sortWordFrequencyMapToSortMap(map);
				page_X_S_s.statistic.setContentType("text/html");
				page.delete(0, page.length());// = new StringBuilder();
				Here: for (int i = fwa.size() - 1; i >= 0; i--) {
					if (fwa.get(i) != null) {
						if (page_X_S_s.pos
								.get(fwa.getW(i).get_word()) == null) {
							page.append("<div style=\"background:white\">"
									+ "<font color=\"black\">"
									+ fwa.getW(i).get_word() + ""
									+ fwa.getW(i).get_frequency()
									+ "</font></div>");
							continue Here;
						}
						if (S_Maps.mingCi.containsKey(fwa.getW(i).get_word())) {
							page.append("<div style=\"background:#FF44FF\">"
									+ "<font color=\"white\">"
									+ fwa.getW(i).get_word() + ""
									+ fwa.getW(i).get_frequency()
									+ "</font></div>");
							continue Here;
						}
						if (S_Maps.dongCi.containsKey(fwa.getW(i).get_word())) {
							page.append("<div style=\"background:#8CEA00\">"
									+ "<font color=\"black\"" + " size=\""
									+ NE.app_S.size_font_rot + "\">"
									+ fwa.getW(i).get_word() + ""
									+ fwa.getW(i).get_frequency()
									+ "</font></div>");
							continue Here;
						}
						if (S_Maps.xingRongCi
								.containsKey(fwa.getW(i).get_word())) {
							page.append("<div style=\"background:#FF9224\">"
									+ "<font color=\"black\"" + " size=\""
									+ NE.app_S.size_font_rot + "\">"
									+ fwa.getW(i).get_word() + ""
									+ fwa.getW(i).get_frequency()
									+ "</font></div>");
						}
					}
				}
				page_X_S_s.statistic.setText(page.toString());
				page_X_S_s.statistic.setSelectionStart(0);
				page_X_S_s.statistic.setSelectionEnd(0);
				page_X_S_s.statistic.validate();
			}
		});
		return buttonPrev;
	}
}
//67 //                            WordFrequency wordFrequency = new WordFrequency();
////                            wordFrequency.I_frequency(1.0);
////                            wordFrequency.I_Word(setOfi);